from reportlab.lib import colors, pagesizes, units
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.platypus import (
    SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageBreak
)
from io import BytesIO
import os


class PDFWriter:
    @classmethod
    def pdf_writer(cls, content: list):
        docs = []
        path = os.getcwd()
        pdfmetrics.registerFont(TTFont('SimSun', path + '/common/simsun.ttc'))
        simsun_style = ParagraphStyle('SimSun', fontName='SimSun', fontSize=12, leading=14)
        # simsun_style.wordWrap = 'CJK'
        # doc = SimpleDocTemplate('translated.pdf', pagesize=pagesizes.letter)
        buffer = BytesIO()
        doc = SimpleDocTemplate(buffer, pagesize=pagesizes.letter)
        for c in content:
            print(type(c))
            para = Paragraph(str(c).strip(), simsun_style)
            docs.append(para)
        doc.build(docs)
        pdf = buffer.getvalue()
        return pdf
